package com.aiyige.page.my.customer.adapter;

import android.support.v4.content.ContextCompat;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.aiyige.R;
import com.aiyige.page.my.customer.callback.ScreenCallback;
import com.aiyige.page.my.customer.model.CustomerScreenFatherEntity;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.LinkedList;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 左侧列表
 * Created by xiachao
 */

public class CustomerScreenLeftAdapter extends BaseQuickAdapter<CustomerScreenFatherEntity, BaseViewHolder> {



    ScreenCallback callback;

    public void setCallback(ScreenCallback callback) {
        this.callback = callback;
    }

    public CustomerScreenLeftAdapter() {
        super(new LinkedList<CustomerScreenFatherEntity>());
    }


    @Override
    protected void convert(BaseViewHolder helper, CustomerScreenFatherEntity item) {
        ((MyHolder) helper).bindData(item);
    }

    @Override
    protected BaseViewHolder onCreateDefViewHolder(ViewGroup parent, int viewType) {
        BaseViewHolder baseViewHolder = new MyHolder(getItemView(R.layout.item_screen_left_class, parent));
        return baseViewHolder;
    }



    public class MyHolder extends BaseViewHolder {
        @BindView(R.id.tv_name)
        TextView tv_name;



        public MyHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
        public void bindData(final CustomerScreenFatherEntity data) {
            setText(R.id.tv_name,data.getName());
            tv_name.setBackgroundColor(ContextCompat.getColor(mContext,data.isSelected()?R.color.white:R.color.zwcolor_gray_f5f7f9));
            tv_name.setTextColor(ContextCompat.getColor(mContext,data.isSelected()?R.color.zwcolor_pink_f93684 :R.color.zwcolor_black_111111));
            tv_name.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (callback != null) {
                        callback.onLeftClick(data);
                    }
                }
            });
        }
    }

}
